home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’92 / PatchWorks Kit / <PatchWorks++> / GenericPatch.c < prev    next >
Text File  |  1992-05-30  |  2KB  |  86 lines

  1. /*
  2.     GenericPatch.c
  3.     
  4.     Higher level patching object. Abstracts a patch as a behavior.
  5.  
  6.     Part of PatchWorks, the Extension Development Framework.
  7.     
  8.     by Mouse Herrell & Patrick Beard.
  9.     
  10.     Permission is granted to use this source code for any purpose, as long
  11.     as the copyright notice is maintained.
  12.     
  13.     © 1992 Berkeley Systems, Inc.
  14.  */
  15.  
  16. #include "GenericPatch.h"
  17.  
  18. void GenericPatch::InitGenericPatch(short trap, long resultOffset)
  19. {
  20.     TrapPatch::InitTrapPatch(GetDispatcher(), trap);
  21.     itsFrame = nil;
  22.     itsResultOffset = resultOffset;
  23. }
  24.  
  25. void GenericPatch::Behavior() {}
  26. PatchProcPtr GenericPatch::GetDispatcher() { return &GenericPatch::Dispatch; }
  27.  
  28. void GenericPatch::AbortTrap()
  29. {
  30.     // adjust the stack back to caller's address.
  31.     itsFrame->offset = itsFrame->parameters + itsResultOffset;
  32. }
  33.  
  34. // default trap dispatching routine.
  35. // if you override GetBehavior above, you can have your behavior routine
  36. // executed directly, with the stack layed out the way you want.
  37.  
  38.  
  39. void GenericPatch::Dispatch(PatchFrame frame)
  40. {    
  41.     GenericPatch* thisPatch;
  42.     PatchFrame* oldFrame;
  43.     
  44. #if defined(THINK_C) && !__option(a4_globals)
  45. #define cDebuggerName "\pTHINK C Debugger 5.0"
  46.     if (EqualString(CurApName, cDebuggerName, false, false))
  47.         return;    // don't get in debugger's way.
  48. #endif
  49.  
  50.     thisPatch = (GenericPatch*)frame.patch;
  51.     oldFrame = thisPatch->itsFrame;
  52.     thisPatch->itsFrame = &frame;
  53.     thisPatch->Behavior();
  54.     thisPatch->itsFrame = oldFrame;
  55. }
  56.  
  57. void GenericVectorPatch::InitGenericVectorPatch(PatchVectorPtr vector, long resultOffset)
  58. {
  59.     VectorPatch::InitVectorPatch(GetDispatcher(), vector);
  60.     itsResultOffset = resultOffset;
  61. }
  62.  
  63. void GenericVectorPatch::Behavior() {}
  64. PatchProcPtr GenericVectorPatch::GetDispatcher() { return &GenericVectorPatch::Dispatch; }
  65.  
  66. void GenericVectorPatch::AbortVector()
  67. {
  68.     // adjust the stack back to caller's address.
  69.     itsFrame->offset = itsFrame->parameters + itsResultOffset;
  70. }
  71.  
  72. // default trap dispatching routine.
  73. // if you override GetBehavior above, you can have your behavior routine
  74. // executed directly, with the stack layed out the way you want.
  75.  
  76. void GenericVectorPatch::Dispatch(PatchFrame frame)
  77. {    
  78.     GenericVectorPatch* thisPatch = (GenericVectorPatch*)frame.patch;
  79. #if defined(THINK_C) && !__option(a4_globals)
  80.     if (EqualString(CurApName, cDebuggerName, false, false))
  81.         return;    // don't get in debugger's way.
  82. #endif
  83.     thisPatch->itsFrame = &frame;
  84.     thisPatch->Behavior();
  85. }
  86.